package com.example.hotel_lxy.ui.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.BaseAdapter;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.example.hotel_lxy.R;
import com.example.hotel_lxy.bean.BeanBean;
import com.example.hotel_lxy.bean.DataInfoBean;
import com.example.hotel_lxy.bean.DataInfoBeanTwo;
import com.example.hotel_lxy.bean.EventBusBean;
import com.example.hotel_lxy.bean.GetUserBean;
import com.example.hotel_lxy.bean.HomeTwoInfoBean;
import com.example.hotel_lxy.bean.ScheduledBean;
import com.example.hotel_lxy.bean.WHBeanTwo;
import com.example.hotel_lxy.net.Api;
import com.example.hotel_lxy.ui.activity.CalendarActivity2;
import com.example.hotel_lxy.ui.activity.LoginActivity;
import com.example.hotel_lxy.ui.activity.MainActivity;
import com.example.hotel_lxy.ui.activity.PotentialInformationActivity;
import com.example.hotel_lxy.ui.activity.ReserveActivity;
import com.example.hotel_lxy.ui.activity.ReserveInformationActivity;
import com.example.hotel_lxy.ui.activity.ZeroPointActivity;
import com.example.hotel_lxy.ui.dialog.HallListDialog;
import com.example.hotel_lxy.utils.DatePhotoUtils;
import com.example.hotel_lxy.utils.DateUtils;
import com.example.hotel_lxy.utils.JurisdictionUtils;
import com.example.hotel_lxy.utils.LunarHelper;
import com.example.hotel_lxy.utils.SPUtils;
import com.example.hotel_lxy.view.NoscrollListView;
import com.example.hotel_lxy.view.SyncHorizontalScrollView;
import com.google.gson.Gson;
import com.ysxsoft.common_base.base.BaseFragment;
import com.ysxsoft.common_base.base.BasePopupWindow;
import com.ysxsoft.common_base.utils.DisplayUtils;
import com.ysxsoft.common_base.utils.JsonUtils;
import com.ysxsoft.common_base.utils.ToastUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import cn.zhouchaoyuan.excelpanel.ExcelPanel;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/***
 *
 * 首页
 *
 */
public class FragmentHome2 extends BaseFragment implements SyncHorizontalScrollView.ScrollViewListener {

    @BindView(R.id.ll_top)
    LinearLayout llTop;
    @BindView(R.id.tv_choice_hall)
    TextView tvChoiceHall;
    @BindView(R.id.tv_main_hotel)
    TextView tvMainHotel;
    @BindView(R.id.tv_main_time)
    TextView tvMainTime;
    @BindView(R.id.text_zero)
    TextView textZero;
    ScheduledBean scheduledBean;

    ExcelPanel excelPanel;

    @BindView(R.id.frame_gr)
    LinearLayout frameGr;
    @BindView(R.id.line1)
    LinearLayout line1;
    @BindView(R.id.line_add_view)
    LinearLayout lineAddView;

    DataInfoBean dataInfoBean;
    @BindView(R.id.lin_year_title)
    LinearLayout linYearTitle;
    @BindView(R.id.header_horizontal)
    SyncHorizontalScrollView headerHorizontal;
    @BindView(R.id.lin_header_content)
    LinearLayout lin_header_content;
    @BindView(R.id.line5)
    LinearLayout line5;

//    private View view;
//    private LinearLayout llTitleContainer;

    private NoscrollListView mLeft;

    private LeftAdapter mLeftAdapter;

    private NoscrollListView mData;

    private DataAdapter mDataAdapter;

//    private SyncHorizontalScrollView mHeaderHorizontal;//星期

    private SyncHorizontalScrollView mDataHorizontal;//内容
    /**
     * excel的列表的数据
     */
    private List<String> mLeftListData;
    /**
     * 最上面的标题的集合
     */
    private List<String> titles;
    /**
     * 标题下方的内容的集合
     */
    private int ys;
    private int ms;
    private int ds;
    private List<String> contents;
    private List<LinearLayout> contentViews;
    private ScaleGestureDetector mScaleGestureDetector = null;

    private LinearLayout linearLayout = null;
    List<List<DataInfoBean.DataBean.ListBean>> mlist = new ArrayList<>();
    String banquet = "";
    String y = "";
    String m = "";
    String d = "";
    private List<String> DataList = new ArrayList<>();

    private float scale;
    private float preScale = 1;// 默认前一次缩放比例为1
    private int x;
    private boolean aBoolean = true;
    private boolean aBooleans = true;
    private List<WHBeanTwo> whBeans = new ArrayList<>();
    private View viewtwo;

    @Override
    public int getLayoutId() {
        return R.layout.fragment_home_activity2;
    }

    private String string1;

    @Override
    protected void doWork(View view) {
        string1 = SPUtils.get(getContext(), "currentDate", "").toString();
        String[] two;
        two = string1.split("-");
        tvMainTime.setText(two[0] + "年" + two[1] + "月");
        y = two[0];
        m = two[1];
        d = two[2];
        ys = Integer.valueOf(y);
        ms = Integer.valueOf(m);
        String substring = d.substring(0, 1);
        if (substring.equals("0")) {
            ds = Integer.valueOf(d.replace("0", ""));
        } else {
            ds = Integer.valueOf(d);
        }
        DataList.add(y + "-" + m);

        initWhInfo();
        initListener();
        mScaleGestureDetector = new ScaleGestureDetector(getContext(),
                new ScaleGestureListener());
        ((MainActivity) this.getActivity()).registerMyTouchListener(myTouchListener);
        String string = SPUtils.get(getContext(), "hotel", "").toString();


        showDateMyMessages();

        initAddView();
    }

    //销控表的动态控件的宽高
    private void initWhInfo() {
        WHBeanTwo whBean = new WHBeanTwo();
        whBean.setW(127);
        whBean.setH(120);
        whBean.setSize(12);
        whBean.setContainerheight(280);
        whBean.setContainerwidth(127);
        whBean.setPmswidth(127);
        whBean.setPmsheight(110);
        whBeans.add(whBean);
    }

    //接口请求
    private void ShowData(final String y, final String m, final String d, final int q) {
        OkHttpClient client = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder()
                .add("year", "" + y)
                .add("month", "" + m)
                .add("banquet", banquet)
                .build();
        Request request = new Request.Builder()
                .url(Api.POST_INDEXQ)
                .addHeader("flag", SPUtils.get(getContext(), "token", "").toString())
                .post(requestBody)
                .build();
        Call call = client.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                new Handler(Looper.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        ToastUtils.shortToast(getContext(), "" + e.getMessage());
                    }
                });
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String responseData = response.body().string();
                BeanBean beanBean = new Gson().fromJson(responseData, BeanBean.class);
                if (beanBean.getCode().equals("0")) {
                    Log.e("TAG", responseData + " ");
                    DataInfoBeanTwo dataInfoBean = new Gson().fromJson(responseData, DataInfoBeanTwo.class);
//                    List<DataInfoBeanTwo.DataBean.ListBean> list=dataInfoBean.getData().getList();
//                    list.addAll(list);
//                    list.addAll(list);
//                    list.addAll(list);

                    initInfo(dataInfoBean, q + "");
                } else if (beanBean.getCode().equals("4")) {
                    SPUtils.put(getContext(), "token", "");
                    Intent intent = new Intent(getContext(), LoginActivity.class).
                            setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    startActivity(intent);
                }
            }
        });
    }

    int total = 0;
    String data1s = "";
    String night = "";
    String sched_ids = "";

    //数据填充处
    private void initInfo(final DataInfoBeanTwo dataInfoBean, String q) {
        int monthLastDay = DateUtils.getMonthLastDay(ys, ms);
        int dayofWeek;
        titles = new ArrayList<String>();

        for (int i = 1; i <= monthLastDay; i++) {
            if (ms < 10) {
                if (i < 10) {
                    dayofWeek = DateUtils.getDayofWeek(y + "-" + m + "-0" + i);
                   // Log.e("TAG", y + "-" + m + "-0" + i + "  4");
                } else {
                    dayofWeek = DateUtils.getDayofWeek(y + "-" + m + "-" + i);
                  //  Log.e("TAG", y + "-" + m + "-" + i + "  3");
                }

            } else {
                if (i < 10) {
                    dayofWeek = DateUtils.getDayofWeek(y + "-" + m + "-0" + i);
                  //  Log.e("TAG", y + "-" + m + "-0" + i + "  2");
                } else {
                    dayofWeek = DateUtils.getDayofWeek(y + "-" + m + "-" + i);
                  //  Log.e("TAG", y + "-" + m + "-" + i + "  1");
                }

            }
            if (dayofWeek == 1) {
                titles.add("周日");
            } else if (dayofWeek == 2) {
                titles.add("周一");
            } else if (dayofWeek == 3) {
                titles.add("周二");
            } else if (dayofWeek == 4) {
                titles.add("周三");
            } else if (dayofWeek == 5) {
                titles.add("周四");
            } else if (dayofWeek == 6) {
                titles.add("周五");
            } else if (dayofWeek == 7) {
                titles.add("周六");
            }
        }
        contents = new ArrayList();
        contents.clear();
        for (int i = 1; i <= monthLastDay; i++) {
            String datetime = "";
            if (i < 10) {
                if (ms < 10) {
                    datetime = ys + "-0" + ms + "-0" + i;
                } else {
                    datetime = ys + "-" + ms + "-0" + i;
                }
            } else {
                if (ms < 10) {
                    datetime = ys + "-0" + ms + "-" + i;
                } else {
                    datetime = ys + "-" + ms + "-" + i;
                }
            }
            contents.add(datetime);
        }
        String string1 = SPUtils.get(getContext(), "homeorder", "").toString();
        if (!string1.equals("")) {
            String[] split1 = string1.split("-");
            data1s = split1[0] + "-" + split1[1] + "-" + split1[2];
            night = split1[3];
            sched_ids = split1[4];
        }
//        View view = View.inflate(getContext(), R.layout.room_status_normal_cell, null);
        getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mLeftListData = new ArrayList();
                mLeftListData.clear();
                contentViews = new ArrayList();
                contentViews.clear();
                linearLayout = null;
                //竖直方向的行数
                long startTime = System.currentTimeMillis();
                Log.e("tag", "startTime:" + startTime);
                total = 0;
                List<DataInfoBeanTwo.DataBean.ListBean> datas = dataInfoBean.getData().getList();
                int size = datas.size();
                for (int i = 0; i < size; i++) {
                    DataInfoBeanTwo.DataBean.ListBean listBean = datas.get(i);
                    mLeftListData.add("" + listBean.getName());
                    Log.e("TAG","TAG   "+listBean.getName());
                    linearLayout = new LinearLayout(getContext());
                    for (final String content : contents) {
                        LayoutInflater layoutInflater = LayoutInflater.from(getContext());

                        View  views = layoutInflater.inflate(R.layout.room_status_normal_cell, null);

                        fill(listBean, content, views);
                        linearLayout.addView(views);
                        total++;
                        long endTime = System.currentTimeMillis();
                        Log.e("tag", "endTime222:" + endTime + "  =" + (endTime - startTime) + " total:" + total);
                    }
                    contentViews.add(linearLayout);
                }

                initDateAddView(titles);
                mLeftAdapter = new LeftAdapter();
                mDataAdapter = new DataAdapter();

                //设置左边栏
                mLeft.setAdapter(mLeftAdapter);
                //设置内容
                mData.setAdapter(mDataAdapter);
                lineAddView.removeAllViews();
                lineAddView.addView(viewtwo);

                aBooleans = true;
                tvMainTime.setText(ys + "年" + ms + "月");
                long endTime3 = System.currentTimeMillis();
                Log.e("tag", "endTime:" + endTime3 + "  =" + (endTime3 - startTime));
            }
        });
    }

    private void initDateAddView(List<String> titles) {
        View views = null;
        linYearTitle.removeAllViews();
        Log.e("tag", titles.size() + "  ");
        for (int i = 0; i < titles.size(); i++) {
            views = View.inflate(getContext(), R.layout.item_rv5, null);
            TextView tvTitle = views.findViewById(R.id.name);
            LinearLayout line2 = views.findViewById(R.id.line2);
            TextView id = views.findViewById(R.id.id);
            int finalI = i;
//            Log.e("tag", finalI + "  132");
            tvTitle.postDelayed(new Runnable() {
                @Override
                public void run() {
                    tvTitle.setText(titles.get(finalI) + "");
                }
            }, 10);
            ViewGroup.LayoutParams layoutParams = tvTitle.getLayoutParams();
            layoutParams.width = whBeans.get(0).getPmswidth() + 6;
            layoutParams.height = whBeans.get(0).getPmsheight();
            tvTitle.setTextSize(whBeans.get(0).getSize());
            ViewGroup.LayoutParams layoutParams1 = id.getLayoutParams();
            layoutParams1.width = whBeans.get(0).getContainerwidth();
            line2.setLayoutParams(layoutParams1);
            linYearTitle.addView(views);
        }
        ViewGroup.LayoutParams layoutParams = line5.getLayoutParams();
        ViewGroup.LayoutParams layoutParams2 = lin_header_content.getLayoutParams();
        ViewGroup.LayoutParams layoutParams3 = headerHorizontal.getLayoutParams();
        ViewGroup.LayoutParams layoutParams4 = linYearTitle.getLayoutParams();


        layoutParams.height = whBeans.get(0).getPmsheight();
        layoutParams2.height = whBeans.get(0).getPmsheight();
        layoutParams3.height = whBeans.get(0).getPmsheight();
        layoutParams4.height = whBeans.get(0).getPmsheight();


        line5.setLayoutParams(layoutParams);
        lin_header_content.setLayoutParams(layoutParams2);
        headerHorizontal.setLayoutParams(layoutParams3);
        linYearTitle.setLayoutParams(layoutParams4);
    }

    private void fill(DataInfoBeanTwo.DataBean.ListBean listBean, String content, View view) {
        LinearLayout pms_cell_container = view.findViewById(R.id.pms_cell_container);//上
        TextView booking_name = view.findViewById(R.id.booking_name);
//        final TextView booking_id = view.findViewById(R.id.booking_id);

        LinearLayout pms_container = view.findViewById(R.id.pms_container);//下
        TextView channel_name = view.findViewById(R.id.channel_name);
//        final TextView channel_id = view.findViewById(R.id.channel_id);

        TextView text = view.findViewById(R.id.text);//宴会厅id
        final String id1 = listBean.getId() + "";
        text.setText("" + id1);

//        TextView types = view.findViewById(R.id.type_s);
//        TextView typex = view.findViewById(R.id.type_x);
//        TextView begin_days = view.findViewById(R.id.begin_day);
//        TextView begin_months = view.findViewById(R.id.begin_month);
//        TextView begin_years = view.findViewById(R.id.begin_year);
//        TextView begin_nights = view.findViewById(R.id.begin_night);
//        TextView director_ids = view.findViewById(R.id.director_id);
//        TextView ids = view.findViewById(R.id.id);
//
//        final TextView title_data = view.findViewById(R.id.title_data);//时间
//        title_data.setText(content);
        HomeTwoInfoBean top = new HomeTwoInfoBean();
        HomeTwoInfoBean bottom = new HomeTwoInfoBean();
        if (listBean.getOrder().size() != 0) {
            for (int j = 0; j < listBean.getOrder().size(); j++) {
                DataInfoBeanTwo.DataBean.ListBean.OrderBean orderBean = listBean.getOrder().get(j);
                String day = orderBean.getDay();//yyyy-mm-dd
                if (day.equals("" + content)) {
                    if (orderBean.getBegin_night() == 1) {//上
                        bottom.setTitle_data(content);
                        top.setTitle_data(content);
                        // types.setText(orderBean.getType() + "");
//                        booking_id.setText("" + orderBean.getId());
//                        begin_days.setText("" + begin_day);
//                        begin_months.setText("" + begin_month);
//                        begin_years.setText("" + begin_year);
//                        begin_nights.setText("" + begin_night);
                        // director_ids.setText("" + director_id);
                        top.setBegin_days(orderBean.getBegin_day());
                        top.setBegin_months(orderBean.getBegin_month());
                        top.setBegin_nights(orderBean.getBegin_night() + "");
                        top.setBegin_years(orderBean.getBegin_year());
                        top.setDirector_ids(orderBean.getDirector_id());
                        top.setId(orderBean.getId() + "");
                        top.setType(orderBean.getType() + "");
                        top.setBid(orderBean.getBid() + "");
                        top.setTitle_data(content);
                        top.setIs_meeting(orderBean.getIs_meeting() + "");
                        if (content.split("-")[2].equals("01")) {
                            if (content.split("-")[1].equals("10")) {
                                booking_name.setText(content.split("-")[1] + "月");
                            } else {
                                booking_name.setText(content.split("-")[1].replace("0", "") + "月");
                            }
                            booking_name.setTextColor(getActivity().getResources().getColor(R.color.Color_f82020));
                        } else {
                            booking_name.setText(content.split("-")[2]);
                        }
                        String string = LunarHelper.SolarToLunarString(Integer.valueOf(content.split("-")[0]), Integer.valueOf(content.split("-")[1]), Integer.valueOf(content.split("-")[2]));
                        if (LunarHelper.Md(string)) {
                            channel_name.setTextColor(getContext().getResources().getColor(R.color.color_FA0101));
                        } else {
                            channel_name.setTextColor(getContext().getResources().getColor(R.color.color_333333));
                        }
                        if (string.equals("十一月")) {
                            channel_name.setText("十一");
                        } else if (string.equals("十二月")) {
                            channel_name.setText("十二");
                        } else {
                            channel_name.setText(string);
                        }
                        if (day.equals("2021-07-26")) {
                            if (night.equals("1")) {
                                if (orderBean.getBid() == 5) {
                                    Log.e("TAG", "");
                                }
                            }
                        }
                        if (orderBean.getType() == 2) {//1潜客2预定
                            if (night.equals("" + orderBean.getBegin_night())) {
                                if (sched_ids.equals("" + orderBean.getBid())) {
                                    if (day.equals("" + data1s)) {
                                        pms_cell_container.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.line_bg_15d37d));
//                                        sched_ids = "";
//                                        SPUtils.put(getContext(), "homeorder", "");
                                    } else {
                                        pms_cell_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_15D37D));
                                    }
                                } else {
                                    if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                        pms_cell_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_15D37D));
                                    }
                                }
                            } else {
                                if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                    pms_cell_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_15D37D));
                                }
                            }
                        } else {
                            if (night.equals("" + orderBean.getBegin_night())) {
                                if (sched_ids.equals("" + orderBean.getBid())) {
                                    if (day.equals("" + data1s)) {
                                        pms_cell_container.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.line_bg_ffca00));
//                                        sched_ids = "";
//                                        SPUtils.put(getContext(), "homeorder", "");
                                    } else {
                                        pms_cell_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_FFCA00));
                                    }
                                } else {
                                    if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                        pms_cell_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_FFCA00));
                                    }
                                }
                            } else {
                                if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                    pms_cell_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_FFCA00));
                                }
                            }
                        }

                    } else {//下
                        bottom.setTitle_data(content);
                        top.setTitle_data(content);
//                        channel_id.setText("" + orderBean.getId());
                        //typex.setText("" + orderBean.getType());
//                        begin_days.setText("" + begin_day);
//                        begin_months.setText("" + begin_month);
//                        begin_years.setText("" + begin_year);
//                        begin_nights.setText("" + begin_night);
                        //director_ids.setText("" + director_id);
                        bottom.setBegin_days(orderBean.getBegin_day());
                        bottom.setBegin_months(orderBean.getBegin_month());
                        bottom.setBegin_nights(orderBean.getBegin_night() + "");
                        bottom.setBegin_years(orderBean.getBegin_year());
                        bottom.setDirector_ids(orderBean.getDirector_id());
                        bottom.setId(orderBean.getId() + "");
                        bottom.setType(orderBean.getType() + "");
                        bottom.setBid(orderBean.getBid() + "");
                        bottom.setTitle_data(content);
                        bottom.setIs_meeting(orderBean.getIs_meeting() + "");

                        String string = LunarHelper.SolarToLunarString(Integer.valueOf(content.split("-")[0]), Integer.valueOf(content.split("-")[1]), Integer.valueOf(content.split("-")[2]));
                        if (LunarHelper.Md(string)) {
                            channel_name.setTextColor(getContext().getResources().getColor(R.color.color_FA0101));
                        } else {
                            channel_name.setTextColor(getContext().getResources().getColor(R.color.color_333333));
                        }
                        if (string.equals("十一月")) {
                            channel_name.setText("十一");
                        } else if (string.equals("十二月")) {
                            channel_name.setText("十二");
                        } else {
                            channel_name.setText(string);
                        }
                        if (content.split("-")[2].equals("01")) {
                            if (content.split("-")[1].equals("10")) {
                                booking_name.setText(content.split("-")[1] + "月");
                            } else {
                                booking_name.setText(content.split("-")[1].replace("0", "") + "月");
                            }
                            booking_name.setTextColor(getActivity().getResources().getColor(R.color.Color_f82020));
                        } else {
                            booking_name.setText(content.split("-")[2]);
                        }
                        if (orderBean.getType() == 2) {//1潜客2预定
                            if (night.equals("" + orderBean.getBegin_night())) {
                                if (sched_ids.equals("" + orderBean.getBid())) {
                                    if (day.equals("" + data1s)) {
                                        pms_container.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.line_bg_15d37d));
//                                        sched_ids = "";
//                                        SPUtils.put(getContext(), "homeorder", "");
                                    } else {
                                        pms_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_15D37D));
                                    }
                                } else {
                                    if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                        pms_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_15D37D));
                                    }
                                }
                            } else {
                                if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                    pms_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_15D37D));
                                }
                            }
                        } else {
                            if (night.equals("" + orderBean.getBegin_night())) {
                                if (sched_ids.equals("" + orderBean.getBid())) {
                                    if (day.equals("" + data1s)) {
                                        pms_container.setBackgroundDrawable(getContext().getResources().getDrawable(R.drawable.line_bg_ffca00));
//                                        sched_ids = "";
//                                        SPUtils.put(getContext(), "homeorder", "");
                                    } else {
                                        pms_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_FFCA00));
                                    }
                                } else {
                                    if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                        pms_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_FFCA00));
                                    }
                                }
                            } else {
                                if (id1.equals("" + orderBean.getBid())) {//宴会厅id
                                    pms_container.setBackgroundColor(getContext().getResources().getColor(R.color.color_FFCA00));
                                }
                            }
                        }
                    }
                } else {
                    bottom.setTitle_data(content);
                    top.setTitle_data(content);
//                    Log.e("TAG",content+"  ");
                    if (content.split("-")[2].equals("01")) {
                        if (content.split("-")[1].equals("10")) {
                            booking_name.setText(content.split("-")[1] + "月");
                        } else {
                            booking_name.setText(content.split("-")[1].replace("0", "") + "月");
                        }
                        booking_name.setTextColor(getActivity().getResources().getColor(R.color.Color_f82020));
                    } else {
                        booking_name.setText(content.split("-")[2]);
                    }
                    String string = LunarHelper.SolarToLunarString(Integer.valueOf(content.split("-")[0]), Integer.valueOf(content.split("-")[1]), Integer.valueOf(content.split("-")[2]));
                    if (LunarHelper.Md(string)) {
                        channel_name.setTextColor(getContext().getResources().getColor(R.color.color_FA0101));
                    } else {
                        channel_name.setTextColor(getContext().getResources().getColor(R.color.color_333333));
                    }
                    if (string.equals("十一月")) {
                        channel_name.setText("十一");
                    } else if (string.equals("十二月")) {
                        channel_name.setText("十二");
                    } else {
                        channel_name.setText(string);
                    }
                }
            }
        } else {
            bottom.setTitle_data(content);
            top.setTitle_data(content);
            if (content.split("-")[2].equals("01")) {
                if (content.split("-")[1].equals("10")) {
                    booking_name.setText(content.split("-")[1] + "月");
                } else {
                    booking_name.setText(content.split("-")[1].replace("0", "") + "月");
                }
                booking_name.setTextColor(getActivity().getResources().getColor(R.color.Color_f82020));
            } else {
                booking_name.setText(content.split("-")[2]);
            }
            String string = LunarHelper.SolarToLunarString(Integer.valueOf(content.split("-")[0]), Integer.valueOf(content.split("-")[1]), Integer.valueOf(content.split("-")[2]));
            if (LunarHelper.Md(string)) {
                channel_name.setTextColor(getContext().getResources().getColor(R.color.color_FA0101));
            } else {
                channel_name.setTextColor(getContext().getResources().getColor(R.color.color_333333));
            }
            if (string.equals("十一月")) {
                channel_name.setText("十一");
            } else if (string.equals("十二月")) {
                channel_name.setText("十二");
            } else {
                channel_name.setText(string);
            }
        }
        //下
        pms_container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String xiaokongbiao = SPUtils.get(getContext(), "xiaokongbiao", "").toString();
                if (xiaokongbiao.equals("1")) {
                    ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                    return;
                }
                if (!bottom.getId().equals("")) {
                    if (bottom.getType().equals("1")) {//潜客
                        boolean sayall = JurisdictionUtils.getSayall(getContext());
                        if (sayall) {
                            boolean saypersonal = JurisdictionUtils.getSaypersonal(getContext());
                            if (saypersonal) {
//                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), bottom.getDirector_ids());
//                                if (getuserid) {
                                    SPUtils.put(getContext(), "currentDate", "");
                                    String[] split = bottom.getTitle_data().split("-");
                                    PotentialInformationActivity.start(id1 + "", split[0] + "",
                                            split[1]  + "", split[2]  + ""
                                            , "2",
                                            id1 + "");
//                                }
                            } else {
                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), bottom.getDirector_ids());
                                if (getuserid) {
                                    ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                                    return;
                                }else{
                                    SPUtils.put(getContext(), "currentDate", "");
                                    String[] split = bottom.getTitle_data().split("-");
                                    PotentialInformationActivity.start(id1 + "", split[0] + "",
                                            split[1]  + "", split[2]  + ""
                                            , "2",
                                            id1 + "");
                                }
                            }


//                            SPUtils.put(getContext(), "currentDate", "");
//                            String[] split = bottom.getTitle_data().split("-");
//                            PotentialInformationActivity.start(id1 + "", split[0] + "",
//                                    split[1]  + "", split[2]  + ""
//                                    , "2",
//                                    id1 + "");
                        } else {
                            boolean saypersonal = JurisdictionUtils.getSaypersonal(getContext());
                            if (saypersonal) {
                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), bottom.getDirector_ids());
                                if (getuserid) {
                                    SPUtils.put(getContext(), "currentDate", "");
                                    String[] split = bottom.getTitle_data().split("-");
                                    PotentialInformationActivity.start(id1 + "", split[0] + "",
                                            split[1]  + "", split[2]  + ""
                                            , "2",
                                            id1 + "");
                                }
                            } else {
                                ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                                return;
                            }
                        }
                        return;
                    } else {//预定
                        boolean sayall = JurisdictionUtils.getSayall(getContext());
                        if (sayall) {
                            SPUtils.put(getContext(), "currentDate", "");
                            ReserveInformationActivity.start(bottom.getId() + "", bottom.getType() + "");
                            return;
                        } else {
                            boolean saypersonal = JurisdictionUtils.getSaypersonal(getContext());
                            if (saypersonal) {
                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), bottom.getDirector_ids());
                                if (getuserid) {
                                    SPUtils.put(getContext(), "currentDate", "");
                                    ReserveInformationActivity.start(bottom.getId() + "", bottom.getType() + "");
                                }
                            } else {
                                ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                                return;
                            }
                        }
                        return;
                    }
                } else {
                    long l = DatePhotoUtils.dateStamp(bottom.getTitle_data());
                    DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = new Date(System.currentTimeMillis());//获取当前时间
                    String currentDate = simpleDateFormat.format(date);
                    long l1 = DatePhotoUtils.dateStamp(currentDate);
                    if (l < l1) {
                        ToastUtils.shortToast(getContext(), "禁止选择之前日期");
                    } else {
                        boolean addscheduled = JurisdictionUtils.getAddscheduled(getContext());
                        if (!addscheduled) {
                            ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                            return;
                        }
                        aBoolean = true;
                        ReserveActivity.start(id1, bottom.getTitle_data() + "-2");
                    }
                }
                //Toast.makeText(getContext(), "下 " + channel_id.getText().toString() + "  " + title_data.getText().toString() + "  " + id1, Toast.LENGTH_SHORT).show();
            }
        });
        //上
        pms_cell_container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!top.getId().equals("")) {
                    if (top.getType().equals("1")) {//潜客
                        boolean sayall = JurisdictionUtils.getSayall(getContext());
                        if (sayall) {
                            boolean saypersonal = JurisdictionUtils.getSaypersonal(getContext());
                            if (saypersonal) {
//                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), top.getDirector_ids());
//                                if (getuserid) {
                                    SPUtils.put(getContext(), "currentDate", "");
                                    String[] split = top.getTitle_data().split("-");
                                    PotentialInformationActivity.start(id1 + "", split[0] + "",
                                            split[1]  + "", split[2]  + ""
                                            , "1",
                                            id1 + "");
//                                }
                            } else {
                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), top.getDirector_ids());
                                if (getuserid) {
                                    ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                                    return;
                                }else{
                                    SPUtils.put(getContext(), "currentDate", "");
                                    String[] split = top.getTitle_data().split("-");
                                    PotentialInformationActivity.start(id1 + "", split[0] + "",
                                            split[1]  + "", split[2]  + ""
                                            , "1",
                                            id1 + "");
                                }
                            }

//                            SPUtils.put(getContext(), "currentDate", "");
//                            String[] split = top.getTitle_data().split("-");
//                            PotentialInformationActivity.start(id1 + "", split[0] + "",
//                                    split[1]  + "", split[2]  + ""
//                                    , "1",
//                                    id1 + "");
                        } else {
                            boolean saypersonal = JurisdictionUtils.getSaypersonal(getContext());
                            if (saypersonal) {
                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), top.getDirector_ids());
                                if (getuserid) {
                                    SPUtils.put(getContext(), "currentDate", "");
                                    String[] split = top.getTitle_data().split("-");
                                    PotentialInformationActivity.start(id1 + "", split[0] + "",
                                            split[1]  + "", split[2]  + ""
                                            , "1",
                                            id1 + "");
                                }
                            } else {
                                ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                                return;
                            }
                        }
                        return;
                    } else {//预定
                        boolean sayall = JurisdictionUtils.getSayall(getContext());
                        if (sayall) {
                            SPUtils.put(getContext(), "currentDate", "");
                            ReserveInformationActivity.start(top.getId() + "", top.getType() + "");
                            return;
                        } else {
                            boolean saypersonal = JurisdictionUtils.getSaypersonal(getContext());
                            if (saypersonal) {
                                boolean getuserid = JurisdictionUtils.getuserid(getContext(), top.getDirector_ids());
                                if (getuserid) {
                                    SPUtils.put(getContext(), "currentDate", "");
                                    ReserveInformationActivity.start(top.getId() + "", top.getType() + "");

                                }
                            } else {
                                ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                                return;
                            }
                        }
                        return;
                    }
                } else {
                    long l = DatePhotoUtils.dateStamp(top.getTitle_data());
                    DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                    Date date = new Date(System.currentTimeMillis());//获取当前时间
                    String currentDate = simpleDateFormat.format(date);
                    long l1 = DatePhotoUtils.dateStamp(currentDate);

                    if (l < l1) {
                        ToastUtils.shortToast(getContext(), "禁止选择之前日期");
                    } else {
                        boolean addscheduled = JurisdictionUtils.getAddscheduled(getContext());
                        if (!addscheduled) {
                            ToastUtils.longToast(getContext(), "当前账号没有操作权限哦");
                            return;
                        }
                        aBoolean = true;
                        if (l == l1) {
                            SimpleDateFormat formatter = new SimpleDateFormat("HH:mm");
                            Date curDate = new Date(System.currentTimeMillis());
                            String time = "00:00-" + formatter.format(curDate);
                            String[] two = time.split("-");
                            String[] second = two[1].split(":");
                            int secondTotalMinute = Integer.valueOf(second[0]) * 60 + Integer.valueOf(second[1]);
                            Log.e("TAG", secondTotalMinute + "  ");
                            if (secondTotalMinute >= 960) {
                                ToastUtils.shortToast(getContext(), "禁止选择之前日期");
                                return;
                            }
                        }
                        ReserveActivity.start(id1, top.getTitle_data() + "-1");
                    }
                }

                //Toast.makeText(getContext(), "上 " + booking_id.getText().toString() + "  " + top.getTitle_data() + "  " + id1, Toast.LENGTH_SHORT).show();
            }
        });
    }


    //动态控件的实例化
    private void initFind(View views) {
        mLeft = views.findViewById(R.id.lv_left);
        mData = views.findViewById(R.id.lv_data);
//        linYearTitle = views.findViewById(R.id.lin_year_title);
        mDataHorizontal = views.findViewById(R.id.data_horizontal);

        headerHorizontal.setScrollViewListener(this);

        mDataHorizontal.setScrollViewListener(this);

        mScaleGestureDetector = new ScaleGestureDetector(getContext(),
                new ScaleGestureListener());

        mDataHorizontal.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                if (mDataHorizontal.getPaddingRight() != 0) {
                    mDataHorizontal.setPadding(0, 0, 0, 0);
                    headerHorizontal.setPadding(0, 0, 0, 0);
                }
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    mDataHorizontal.startScrollerTask();
                }
                return false;
            }
        });
        mDataHorizontal.setOnScrollStopListner(new SyncHorizontalScrollView.OnScrollStopListner() {
            @Override
            public void onScrollStoped() {

            }

            @Override
            public void onScrollToLeftEdge() {
                if (aBooleans) {
                    aBooleans = false;
                    if (ms <= 1) {
                        ys = ys - 1;
                        ms = 12;
                    } else {
                        ms = ms - 1;
                    }
                    ds = 1;
                    y = ys + "";
                    m = ms + "";
                    d = "01";
                    SPUtils.put(getContext(), "homeorder", "");
                    initAddView();
                }

            }

            @Override
            public void onScrollToRightEdge() {
                if (aBooleans) {
                    aBooleans = false;
                    if (ms >= 12) {
                        ys = ys + 1;
                        ms = 1;
                    } else {
                        ms = ms + 1;
                    }
                    ds = 1;
                    y = ys + "";
                    m = ms + "";
                    d = "01";
                    SPUtils.put(getContext(), "homeorder", "");
                    initAddView();
                }
            }

            @Override
            public void onScrollToMiddle() {

            }
        });
        if (ms < 10) {
            Log.e("TAG", "1");
            ShowData(ys + "", "0" + ms, "" + ds, 1);
        } else {
            Log.e("TAG", "2");
            ShowData(ys + "", "" + ms, "" + ds, 1);
        }
        mDataHorizontal.post(new Runnable() {
            @Override
            public void run() {
                mDataHorizontal.measure(0, 0);
                int x = mDataHorizontal.getMeasuredWidth();
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mLeft.getLayoutParams();
                int listw = DisplayUtils.getDisplayWidth(getActivity()) - mLeft.getWidth();


                int offsetX = listw - x + ds * whBeans.get(0).getW() - whBeans.get(0).getW() - params.leftMargin * 2;
//                Log.e("TAG",whBeans.get(0).getW()+"  "+params.leftMargin+"  "+offsetX+"   "+ds);
                mDataHorizontal.setPadding(0, 0, offsetX, 0);
                mDataHorizontal.smoothScrollTo(ds * whBeans.get(0).getW() - whBeans.get(0).getW(), 0);

                headerHorizontal.setPadding(0, 0, offsetX, 0);
                headerHorizontal.smoothScrollTo(ds * whBeans.get(0).getW() - whBeans.get(0).getW(), 0);
            }
        });
    }

    //动态布局
    private void initAddView() {
        viewtwo = LinearLayout.inflate(getContext(), R.layout.add_viewtwo, null);
        viewtwo.setTag(lineAddView.getChildCount());//设置标记
        initFind(viewtwo);
        viewtwo.setPadding(0, 0, 0, 0);
    }

    @Override
    public void onScrollChanged(SyncHorizontalScrollView scrollView, int x, int y, int oldx, int oldy) {
        if (scrollView == headerHorizontal) {
            mDataHorizontal.scrollTo(x, y);
        } else if (scrollView == mDataHorizontal) {
            headerHorizontal.scrollTo(x, y);
        }
    }


    private void showDateMyMessages() {
        String token = SPUtils.get(getContext(), "token", "").toString();
        OkHttpUtils.post()
                .url(Api.POST_USER_GETUSER)
                .addHeader("flag", token)
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "我的首页1onResponse~~~~~~~~    " + e.getMessage());
                        showDateMyMessages();
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "我的首页1onResponse~~~~~~~~    " + response);
                        BeanBean beanBean = JsonUtils.parseByGson(response, BeanBean.class);
                        if (beanBean.getCode().equals("4")) {
                            SPUtils.put(getContext(), "token", "");
                            Intent intent = new Intent(getContext(), LoginActivity.class).
                                    setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            return;
                        }
                        if (beanBean.getCode().equals("0")) {
                            GetUserBean getUserBean = JsonUtils.parseObject(response, GetUserBean.class);
                            SPUtils.put(getContext(), "hotel", "" + getUserBean.getData().getList().getHotel());
                            tvMainHotel.setText(getUserBean.getData().getList().getHotel() + "");
                        }
                    }
                });
    }

    private void initListener() {
        OkHttpUtils.post()
                .url(Api.POST_INDEX_SCHEDULED)
                .addHeader("flag", SPUtils.get(getContext(), "token", "").toString())
                .tag(this)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Call call, Exception e, int id) {
                        Log.e("TAG", "宴会厅onError   " + e.getMessage());
                    }

                    @Override
                    public void onResponse(String response, int id) {
                        Log.e("TAG", "宴会厅onResponse   " + response);
                        if (response.equals("")) {
//                            ys = Integer.valueOf(y);
//                            ms = Integer.valueOf(m);
//                            String substring = d.substring(0, 1);
//                            if (substring.equals("0")) {
//                                ds = Integer.valueOf(d.replace("0", ""));
//                            } else {
//                                ds = Integer.valueOf(d);
//                            }
                            return;
                        }
                        BeanBean beanBean = JsonUtils.parseObject(response, BeanBean.class);
                        if (beanBean.getCode().equals("0")) {
                            scheduledBean = JsonUtils.parseByGson(response, ScheduledBean.class);
                            for (int i = 0; i < scheduledBean.getData().size(); i++) {
                                tvChoiceHall.setText(scheduledBean.getData().get(0).getName());
                                banquet = scheduledBean.getData().get(0).getId() + "";
                                SPUtils.put(getContext(), "name", scheduledBean.getData().get(0).getName());
                                SPUtils.put(getContext(), "sched_id", scheduledBean.getData().get(0).getId() + "");
                                SPUtils.put(getContext(), "max", scheduledBean.getData().get(0).getMax() + "");
                            }
//                            ys = Integer.valueOf(y);
//                            ms = Integer.valueOf(m);
//                            String substring = d.substring(0, 1);
//                            if (substring.equals("0")) {
//                                ds = Integer.valueOf(d.replace("0", ""));
//                            } else {
//                                ds = Integer.valueOf(d);
//                            }
                        } else if (beanBean.getCode().equals("4")) {
                            SPUtils.put(getContext(), "token", "");
                            SPUtils.put(getContext(), "id", "");
                            Intent intent = new Intent(getContext(), LoginActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    }
                });
        tvChoiceHall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showChoiceHallDialog(view);
            }
        });
        tvMainHotel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // showHotelDialog(view);
            }
        });
        boolean notenabled = JurisdictionUtils.getNotenabled(getContext());
        if (notenabled) {
            textZero.setVisibility(View.GONE);
        } else {
            textZero.setVisibility(View.VISIBLE);
        }
        textZero.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String xiaokongbiao = SPUtils.get(getContext(), "xiaokongbiao", "").toString();
                if (xiaokongbiao.equals("1")) {
                    ToastUtils.shortToast(getContext(), "前账号没有操作权限哦");
                    return;
                }

                ZeroPointActivity.start();
            }
        });
        tvMainTime.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                CalendarActivity.start(3);
                String[] two;
                two = string1.split("-");

                CalendarActivity2.start(Integer.valueOf(two[0]), Integer.valueOf(two[1]) - 1, 2);
            }
        });
    }


    private void showChoiceHallDialog(View view) {
        if (scheduledBean != null && scheduledBean.getCode().equals("0")) {
            if (scheduledBean.getData().size() == 0) {
                return;
            }
            new HallListDialog.Builder(getActivity()).setList(scheduledBean.getData()).setOnListener(new HallListDialog.OnListener() {
                @Override
                public void onSelected(BasePopupWindow popupWindow, int position) {
                    tvChoiceHall.setText(scheduledBean.getData().get(position).getName());
                    banquet = scheduledBean.getData().get(position).getId() + "";
                    SPUtils.put(getContext(), "name", scheduledBean.getData().get(position).getName());
                    SPUtils.put(getContext(), "sched_id", scheduledBean.getData().get(position).getId() + "");
                    SPUtils.put(getContext(), "max", scheduledBean.getData().get(position).getMax());
                    String replace = tvMainTime.getText().toString().replace("年", "-").replace("月", "-");
                    String[] two = replace.split("-");
                    y = two[0];
                    m = two[1];
                    ys = Integer.valueOf(y);
                    ms = Integer.valueOf(m);
                    String substring = d.substring(0, 1);
                    if (substring.equals("0")) {
                        ds = Integer.valueOf(d.replace("0", ""));
                    } else {
                        ds = Integer.valueOf(d);
                    }
                    if (Integer.valueOf(m) < 10) {
                        Log.e("TAG", "3");
                        ShowData(y, "0" + m, d, 5);
                    } else {
                        Log.e("TAG", "4");
                        ShowData(y, m, d, 5);
                    }

                }
            }).showAsDropDown(view);
        }
    }

    // 普通事件的处理
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void handleEvent(EventBusBean carrier) {
        if (carrier != null) {
            if (carrier.getStarttime() == null) {
                return;
            }
            String[] two = carrier.getStarttime().split("-");
            //tvMainTime.setText(two[0]+"年" +two[1]+"月");
            y = two[0];
            m = two[1];
            d = two[2];
            ys = Integer.valueOf(y);
            ms = Integer.valueOf(m);
            String substring = d.substring(0, 1);
            if (substring.equals("0")) {
                ds = Integer.valueOf(d.replace("0", ""));
            } else {
                ds = Integer.valueOf(d);
            }
            SPUtils.put(getContext(), "currentDate", y + "-" + m + "-" + d);
            initAddView();
//            Log.e("TAG","5");
//            ShowData(two[0], two[1], two[2], 4);
        }
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);  //事件的注册
    }

    @Override
    public void onPause() {
        super.onPause();
        ((MainActivity) this.getActivity()).unRegisterMyTouchListener(myTouchListener);
        aBoolean = true;
    }

    @Override
    public void onResume() {
        super.onResume();
        ((MainActivity) this.getActivity()).registerMyTouchListener(myTouchListener);
        String string = SPUtils.get(getContext(), "aBoolean", "").toString();
        if (aBoolean) {
            if (string.equals("1")) {
                String string1 = SPUtils.get(getContext(), "currentDate", "").toString();
                if (!string1.equals("")) {
                    String[] two = string1.split("-");
                    tvMainTime.setText(two[0] + "年" + two[1] + "月");
                    y = two[0];
                    m = two[1];
                    d = two[2];
                    String substring = d.substring(0, 1);
                    if (substring.equals("0")) {
                        ds = Integer.valueOf(d.replace("0", ""));
                    } else {
                        ds = Integer.valueOf(d);
                    }
                    mlist.clear();
                    initAddView();
//                    Log.e("TAG","6");
//                    ShowData(y, m, d, 6);
                }
                SPUtils.put(getContext(), "aBoolean", "2");
            }
            aBoolean = false;
        }

    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        if (hidden) {//不可见
            SPUtils.put(getContext(), "aBoolean", "2");
            ((MainActivity) this.getActivity()).unRegisterMyTouchListener(myTouchListener);
        } else {//可见
            ((MainActivity) this.getActivity()).registerMyTouchListener(myTouchListener);
        }
        if (hidden) {
            if (EventBus.getDefault().isRegistered(this)) {
                EventBus.getDefault().unregister(this); //解除注册
            }
        } else {
            String string1 = SPUtils.get(getContext(), "currentDate", "").toString();
            if (!string1.equals("")) {
                String[] two = string1.split("-");
                tvMainTime.setText(two[0] + "年" + two[1] + "月");
                y = two[0];
                m = two[1];
                // d = two[2];
                ys = Integer.valueOf(y);
                ms = Integer.valueOf(m);
//                String substring = d.substring(0, 1);
//                if (substring.equals("0")) {
//                    ds = Integer.valueOf(d.replace("0", ""));
//                } else {
//                    ds = Integer.valueOf(d);
//                }
                String string = SPUtils.get(getContext(), "aBoolean", "").toString();
                if (!string.equals("1")) {
                    initAddView();
                }

                // ShowData(y, m, d, 6);
                if (!EventBus.getDefault().isRegistered(this)) {
                    EventBus.getDefault().register(this);  //事件的注册
                }
            } else {
                ys = Integer.valueOf(y);
                ms = Integer.valueOf(m);
//                String substring = d.substring(0, 1);
//                if (substring.equals("0")) {
//                    ds = Integer.valueOf(d.replace("0", ""));
//                } else {
//                    ds = Integer.valueOf(d);
//                }
                String string = SPUtils.get(getContext(), "aBoolean", "").toString();
                if (!string.equals("1")) {
                    initAddView();
                }
                // ShowData(y, m, d, 6);
                if (!EventBus.getDefault().isRegistered(this)) {
                    EventBus.getDefault().register(this);  //事件的注册
                }
            }

        }
    }


    MainActivity.MyTouchListener myTouchListener = new MainActivity.MyTouchListener() {
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            //处理手势事件（根据个人需要去返回和逻辑的处理）
            int pointerCount = event.getPointerCount(); // 获得多少点
            if (pointerCount > 1) {// 多点触控，
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        break;
                    case MotionEvent.ACTION_MOVE:
                        break;
                    case MotionEvent.ACTION_POINTER_2_UP://第二个手指抬起的时候
                        break;
                    default:
                        break;
                }
                return mScaleGestureDetector.onTouchEvent(event);//让mScaleGestureDetector处理触摸事件
            }
            return false;
        }
    };

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ((MainActivity) this.getActivity()).unRegisterMyTouchListener(myTouchListener);
    }

    class LeftAdapter extends BaseAdapter {
        @Override

        public int getCount() {
            return mLeftListData.size();

        }

        @Override

        public Object getItem(int position) {
            return mLeftListData.get(position);

        }

        @Override

        public long getItemId(int position) {
            return position;

        }

        @Override

        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder = null;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_left, null);
                holder.tvLeft = convertView.findViewById(R.id.tv_left);
                holder.line1 = convertView.findViewById(R.id.line1);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }

            ViewGroup.LayoutParams layoutParams = holder.tvLeft.getLayoutParams();
            holder.tvLeft.setTextSize(whBeans.get(0).getSize());

//            layoutParams.height = whBeans.get(0).getPmsheight()*2+10;
            layoutParams.height = whBeans.get(0).getContainerheight();
            holder.line1.setLayoutParams(layoutParams);

            holder.tvLeft.setText("" + mLeftListData.get(position) + "");

            return convertView;

        }

        class ViewHolder {
            TextView tvLeft;
            LinearLayout line1;
        }
    }


    class DataAdapter extends BaseAdapter {
        @Override

        public int getCount() {
            return mLeftListData.size();

        }

        @Override

        public Object getItem(int position) {
            return mLeftListData.get(position);

        }

        @Override

        public long getItemId(int position) {
            return position;
        }

        @Override

        public View getView(final int position, View convertView, ViewGroup parent) {

            final LinearLayout vv = contentViews.get(position);
            for (int i = 0; i < vv.getChildCount(); i++) {
                View child = vv.getChildAt(i);

                LinearLayout pms_cell_container = child.findViewById(R.id.pms_cell_container);//上
                LinearLayout pms_container = child.findViewById(R.id.pms_container);//下
                TextView booking_name = child.findViewById(R.id.booking_name);
                TextView channel_name = child.findViewById(R.id.channel_name);

                LinearLayout line3 = child.findViewById(R.id.line2);
                ViewGroup.LayoutParams layoutParams1 = line3.getLayoutParams();
//                layoutParams1.width = whBeans.get(0).getPmswidth()+3;
//                layoutParams1.height = whBeans.get(0).getPmsheight()*2+10;

                layoutParams1.width = whBeans.get(0).getContainerwidth();
                layoutParams1.height = whBeans.get(0).getContainerheight();
                line3.setLayoutParams(layoutParams1);


                booking_name.setTextSize(whBeans.get(0).getSize());
                channel_name.setTextSize(whBeans.get(0).getSize());
                ViewGroup.LayoutParams layoutParams = pms_cell_container.getLayoutParams();
                layoutParams.width = whBeans.get(0).getPmswidth() - 5;
                layoutParams.height = whBeans.get(0).getPmsheight();
                pms_cell_container.setLayoutParams(layoutParams);

                ViewGroup.LayoutParams layoutParams2 = pms_container.getLayoutParams();
                layoutParams2.width = whBeans.get(0).getPmswidth() - 5;
                layoutParams2.height = whBeans.get(0).getPmsheight();
                pms_container.setLayoutParams(layoutParams2);

            }

            return vv;
        }

    }

    public class ScaleGestureListener implements
            ScaleGestureDetector.OnScaleGestureListener {

        @Override
        public boolean onScale(ScaleGestureDetector detector) {
            float previousSpan = detector.getPreviousSpan();// 前一次双指间距
            float currentSpan = detector.getCurrentSpan();// 本次双指间距
            int w = whBeans.get(0).getW();
            int h = whBeans.get(0).getH();
            int size = whBeans.get(0).getSize();

            int containerheight = whBeans.get(0).getContainerheight();
            int containerwidth = whBeans.get(0).getContainerwidth();
            int pmsheight = whBeans.get(0).getPmsheight();
            int pmswidth = whBeans.get(0).getPmswidth();
            ViewGroup.LayoutParams layoutParams1 = line5.getLayoutParams();
            if (currentSpan < previousSpan) {
                // 缩小
                scale = preScale - (previousSpan - currentSpan) / 1000;
                if (w >= (127 - 20)) {
                    whBeans.clear();
                    WHBeanTwo whBean = new WHBeanTwo();
                    whBean.setW(w - 5);
                    whBean.setH(h - 5);
                    whBean.setSize(size - 1);
                    whBean.setContainerwidth(containerwidth - 5);
                    whBean.setContainerheight(containerheight - 5);
                    whBean.setPmsheight(pmsheight - 5);
                    whBean.setPmswidth(pmswidth - 5);
                    whBeans.add(whBean);

                    mLeftAdapter.notifyDataSetChanged();
                    mDataAdapter.notifyDataSetChanged();

                    for (int i = 0; i < linYearTitle.getChildCount(); i++) {
                        View childAt = linYearTitle.getChildAt(i);
                        TextView name = childAt.findViewById(R.id.name);
                        TextView id = childAt.findViewById(R.id.id);
                        ViewGroup.LayoutParams layoutParams = name.getLayoutParams();
                        LinearLayout line2 = childAt.findViewById(R.id.line2);
                        layoutParams.width = whBeans.get(0).getPmswidth() + 6;
//                        layoutParams.height = whBeans.get(0).getPmsheight();
                        name.setTextSize(whBeans.get(0).getSize() - 2);
                        name.setLayoutParams(layoutParams);

                        ViewGroup.LayoutParams layoutParams2 = id.getLayoutParams();
                        layoutParams2.width = whBeans.get(0).getContainerwidth();
                        line2.setLayoutParams(layoutParams2);
                    }

                    ViewGroup.LayoutParams layoutParams = line5.getLayoutParams();
                    ViewGroup.LayoutParams layoutParams2 = lin_header_content.getLayoutParams();
                    ViewGroup.LayoutParams layoutParams3 = headerHorizontal.getLayoutParams();
                    ViewGroup.LayoutParams layoutParams4 = linYearTitle.getLayoutParams();


                    layoutParams.height = whBeans.get(0).getPmsheight();
                    layoutParams2.height = whBeans.get(0).getPmsheight();
                    layoutParams3.height = whBeans.get(0).getPmsheight();
                    layoutParams4.height = whBeans.get(0).getPmsheight();


                    line5.setLayoutParams(layoutParams);
                    lin_header_content.setLayoutParams(layoutParams2);
                    headerHorizontal.setLayoutParams(layoutParams3);
                    linYearTitle.setLayoutParams(layoutParams4);
                }

            } else {
                // 放大
                scale = preScale + (currentSpan - previousSpan) / 1000;
                if (w <= (127 + 20)) {
                    whBeans.clear();
                    WHBeanTwo whBean = new WHBeanTwo();
                    whBean.setW(w + 5);
                    whBean.setH(h + 5);
                    whBean.setSize(size + 1);
                    whBean.setContainerwidth(containerwidth + 5);
                    whBean.setContainerheight(containerheight + 5);
                    whBean.setPmsheight(pmsheight + 5);
                    whBean.setPmswidth(pmswidth + 5);
                    whBeans.add(whBean);

                    layoutParams1.height = h + 5;
                    line5.setLayoutParams(layoutParams1);

                    mLeftAdapter.notifyDataSetChanged();
                    mDataAdapter.notifyDataSetChanged();

                    for (int i = 0; i < linYearTitle.getChildCount(); i++) {
                        View childAt = linYearTitle.getChildAt(i);
                        TextView name = childAt.findViewById(R.id.name);
                        LinearLayout line2 = childAt.findViewById(R.id.line2);
                        ViewGroup.LayoutParams layoutParams = name.getLayoutParams();
                        layoutParams.width = whBeans.get(0).getPmswidth() + 6;
//                        layoutParams.height = whBeans.get(0).getPmsheight();
                        name.setTextSize(whBeans.get(0).getSize() + 2);
                        name.setLayoutParams(layoutParams);

                        TextView id = childAt.findViewById(R.id.id);
                        ViewGroup.LayoutParams layoutParams2 = id.getLayoutParams();
                        layoutParams2.width = whBeans.get(0).getContainerwidth();
                        line2.setLayoutParams(layoutParams2);
                    }

                    ViewGroup.LayoutParams layoutParams = line5.getLayoutParams();
                    ViewGroup.LayoutParams layoutParams2 = lin_header_content.getLayoutParams();
                    ViewGroup.LayoutParams layoutParams3 = headerHorizontal.getLayoutParams();
                    ViewGroup.LayoutParams layoutParams4 = linYearTitle.getLayoutParams();

                    layoutParams.height = whBeans.get(0).getPmsheight();
                    layoutParams2.height = whBeans.get(0).getPmsheight();
                    layoutParams3.height = whBeans.get(0).getPmsheight();
                    layoutParams4.height = whBeans.get(0).getPmsheight();


                    line5.setLayoutParams(layoutParams);
                    lin_header_content.setLayoutParams(layoutParams);
                    headerHorizontal.setLayoutParams(layoutParams);
                    linYearTitle.setLayoutParams(layoutParams4);

                }
            }
            return false;
        }

        @Override
        public boolean onScaleBegin(ScaleGestureDetector detector) {
            // 一定要返回true才会进入onScale()这个函数
            return true;
        }

        @Override
        public void onScaleEnd(ScaleGestureDetector detector) {
            preScale = scale;// 记录本次缩放比例
            // ShowData(y, m, d, 6);
        }
    }
}